#include "InputBox.h"

InputBox::InputBox(const Point2D& position, uint32 background_color, SDL_Color font_color)
    : Rectangle(Point2D(200,16), position, background_color), 
      _font_color(font_color), 
      _handle_char_press(this,&InputBox::WriteCharacter)
{
    KeyboardEvents::GetInstance()->OnCharacterPressed().Subscribe(&_handle_char_press);
}

void InputBox::WriteCharacter(char c)
{
    _current_text += c;
    //printf("%s\n",_current_text.c_str());
}

void InputBox::Render(SDL_Surface* surface)
{
    Rectangle::Render(surface);
    
    SDL_Surface* text = Font::RenderText(_current_text.c_str(),SDL_Color(_font_color));
    
    SDL_Rect r;
    r.x = offset.x;
    r.y = offset.y;
    
    SDL_BlitSurface( text, NULL, surface, &r );
}

const string& InputBox::GetText() const
{
    return _current_text;
}

